#include <iostream>
#include <algorithm>
using std::cin;
using std::cout;
using std::endl;
    int i;
    int j;
    int len1;
    int len2;
    int a[i][j];
int exc(int key){
        len1=i,len2=j;
    if(key==0){
            j=len2-(j-1);
            cout<<a[i][j]<<endl;
        }
    else{
        i=len1-(i-1);
        cout<<a[i][j]<<endl;
    }
    return a[i][j];
}
int main(){
    int key;
    cin>>i>>j>>key;
    cin>>a[i][j];
    exc(key);
    return 0;
}